package com.cn.kabalifeuser.ui.order.activity;

import com.cn.kabalifeuser.api.Api;
import com.cn.kabalifeuser.base.BasePresenter;
import com.cn.kabalifeuser.callback.CacheCallBack;
import com.cn.kabalifeuser.config.Constants;
import com.cn.kabalifeuser.ui.login.bean.MsgBean;
import com.cn.kabalifeuser.ui.order.bean.OrderDetailsAfterSaleBean;
import com.cn.kabalifeuser.ui.order.bean.OrderDetailsBean;
import com.cn.kabalifeuser.utils.LoggerUtils;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

/**
 * Created by 晓林 on 2020/9/25.
 * function:
 */
public class MallOrderAfterSaleDetailsPresenter extends BasePresenter<MallOrderAfterSaleDetailsView> {

    public void onOrderDetailsData(String token, int id) {
        OkGo.<OrderDetailsAfterSaleBean>get(Api.API_ORDER_DETAIL_AFTER)
                .headers("token", token)
                .params("id", id)
                .execute(new CacheCallBack<OrderDetailsAfterSaleBean>() {
                    @Override
                    public void onSuccess(Response<OrderDetailsAfterSaleBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("詳情：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onOrderDetailsSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }

    public void onAfterData(String token, int id, String express_name, String express_num) {
        OkGo.<MsgBean>post(Api.API_ORDER_DETAIL_AFTER_NO)
                .headers("token", token)
                .params("id", id)
                .params("express_name", express_name)
                .params("express_num", express_num)
                .execute(new CacheCallBack<MsgBean>() {
                    @Override
                    public void onSuccess(Response<MsgBean> response) {
                        super.onSuccess(response);
                        LoggerUtils.e("詳情：" + response.body());
                        if (isViewAttached())
                            if (response.body().getCode() == Constants.HTTP_SUCCESS)
                                getView().onAfterSuccess(response.body());
                            else if (response.body().getCode() == Constants.HTTP_AGAIN_LOGIN)
                                getView().onReLoggedIn(response.body().getMsg());
                            else
                                getView().onError(response.body().getMsg());
                    }
                });
    }
}
